#pragma once
#include "stdafx.h"
#include "IEventHandler.h"
#include "ServiceHandler.h"
#include "SOCK_Connector.h"
#include "INET_Addr.h"
#include "IReactor.h"
#include "Handler.h"

template<typename T>
class IConnector: public IEventHandler<T>
{
public:
	IConnector(IReactor<T>* _reactor): reactor(_reactor){}
	void connect(ServiceHandler<T>* serviceHand, INET_Addr* addr)
	{
		connect_service_handle(serviceHand, addr);
	}
	virtual void handle_event(Handler<T> handle, Event_Type et)
	{
		complete(handle);
	}
protected:
	virtual void complete(Handler<T>) = 0;
	virtual void connect_service_handle(ServiceHandler<T>* serviceHand, INET_Addr*) = 0;
	virtual void activate_service_handle(ServiceHandler<T>&) = 0;
	IReactor<T>* reactor;
	ServiceHandler<T>* service;	
	SOCK_Stream stream;
	SOCK_Connector connector;
};